package pl.edu.mimuw.irs.rcp.controller.editor.input;

import java.util.LinkedHashMap;
import java.util.Map;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IPersistableElement;

import pl.edu.mimuw.irs.core.model.design.processing.Resource;
import pl.edu.mimuw.irs.core.model.design.processing.Role;

public class ResourceEditorInput implements IEditorInput {

	// *** Attributes

	private Resource resource;
	private Map<String, Role> rolesMap;
	public Resource getResource() {
		return resource;
	}
	public Map<String, Role> getRolesMap() {
		if (rolesMap == null) rolesMap = new LinkedHashMap<String, Role>();
		return rolesMap;
	}
	
	// *** Constructors
	
	public ResourceEditorInput(Resource resource, Map<String, Role> rolesMap) {
		this.resource = resource;
		this.rolesMap = rolesMap;
	}
	
	// *** Methods
	
	@Override
	public boolean exists() {
		return false;
	}

	@Override
	public ImageDescriptor getImageDescriptor() {
		return null;
	}

	@Override
	public String getName() {
		return resource.getName();
	}

	@Override
	public IPersistableElement getPersistable() {
		return null;
	}

	@Override
	public String getToolTipText() {
		return resource.getName();
	}

	@SuppressWarnings("unchecked")
	@Override
	public Object getAdapter(Class adapter) {
		// XXX : Auto-generated method stub
		return null;
	}

	@Override
	public boolean equals(Object obj) {
		if (super.equals(obj)) {
			return true;
		}
		if (obj instanceof ResourceEditorInput) {
			return resource.equals(((ResourceEditorInput)obj).getResource());
		}
		return false;
	}

	@Override
	public int hashCode() {
		return resource.hashCode();
	}

}
